package org.wmq.travelagency02.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.wmq.travelagency02.mapper.ScenicSpotMapper;
import org.wmq.travelagency02.model.Entity.Route;
import org.wmq.travelagency02.model.Entity.ScenicSpot;
import org.wmq.travelagency02.service.RouteService;
import org.wmq.travelagency02.service.ScenicSpotService;

import java.util.List;

@Service
@RequiredArgsConstructor
public class ScenicSpotServiceImpl extends ServiceImpl<ScenicSpotMapper, ScenicSpot> implements ScenicSpotService {
    private final RouteService routeService;

    @Override
    public ScenicSpot getById(Long id) {
        ScenicSpot result = this.lambdaQuery().eq(ScenicSpot::getId, id).
                select(
                        ScenicSpot::getName,
                        ScenicSpot::getDescription,
                        ScenicSpot::getLongitude,
                        ScenicSpot::getLatitude
                ).one();
        if (result == null) {
            return null;
        }
        result.setId(id);
        return result;
    }

    @Override
    public boolean removeById(Long id) {
        List<Route> routeList = this.routeService.list();
        for (Route route : routeList){
            if (route.getContent().contains(id)){
                return false;
            }
        }
        return super.removeById(id);
    }
}
